{% extends 'dcim/device/base.html' %}
{% load static %}

{% block title %}{{ object }} - LLDP Neighbors{% endblock %}

{% block head %}
<script type="text/javascript" src="{% static 'lldp.js' %}" onerror="window.location='{% url 'media_failure' %}?filename=lldp.js'"></script>
{% endblock %}

{% block content %}
    <div class="card">
        <div class="card-overlay">
            <div class="spinner-border" role="status">
                <span class="visually-hidden">Loading...</span>
            </div>
        </div>
        <div class="card-header">
            <h5 class="d-inline">LLDP Neighbors</h5>
        </div>
        <div class="card-body">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>Interface</th>
                        <th>Configured Device</th>
                        <th>Configured Interface</th>
                        <th>LLDP Device</th>
                        <th>LLDP Interface</th>
                    </tr>
                </thead>
                <tbody>
                    {% for iface in interfaces %}
                        <tr id="{{ iface.name }}">
                            <td>{{ iface }}</td>
                            {% with peer=iface.connected_endpoints.0 %}
                              {% if peer.device %}
                                  <td class="configured_device" data="{{ peer.device.name }}" data-chassis="{{ peer.device.virtual_chassis.name }}">
                                      <a href="{% url 'dcim:device' pk=peer.device.pk %}">{{ peer.device }}</a>
                                  </td>
                                  <td class="configured_interface" data="{{ peer.name }}">
                                      <span title="{{ peer.get_type_display }}">{{ peer }}</span>
                                  </td>
                              {% elif peer.circuit %}
                                  {% with circuit=peer.circuit %}
                                      <td colspan="2">
                                          <i class="mdi mdi-lightning-bolt" title="Circuit"></i>
                                          <a href="{{ circuit.get_absolute_url }}">{{ circuit.provider }} {{ circuit }}</a>
                                      </td>
                                  {% endwith %}
                              {% else %}
                                  <td class="text-muted" colspan="2">None</td>
                              {% endif %}
                            {% endwith %}
                            <td class="device"></td>
                            <td class="interface"></td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}

{% block data %}
<span data-object-url="{% url 'dcim-api:device-napalm' pk=object.pk %}?method=get_lldp_neighbors_detail"></span>
{% endblock %}
